<template>
  <el-row>
    <a download="model.xlsx" :href="'/api/teacher/getExcelModel?tk='+fileUpHead.tk">下载excel模板</a>
  </el-row>
  <el-row>
    <el-col :span="6">
      <el-upload
          ref="upload"
          class="upload-demo"
          action="/api/teacher/AddStudentByExcel"
          :limit="1"
          :headers="fileUpHead"
          :on-exceed="handleExceed"
          :auto-upload="false"
      >
        <template #trigger>
          <el-button type="primary">选择表格</el-button>
        </template>
        <el-button class="ml-3" type="success" @click="submitUpload"
        >上传
        </el-button>
        <template #tip>
          <div class="el-upload__tip" style="color: red">
            表名为默认的Sheet1 第一二三四列：学号，班级，姓名，密码<br/>学号相同会覆盖
          </div>
        </template>
      </el-upload>

    </el-col>
  </el-row>
</template>

<script>
import axios from "axios";
import {ElMessage} from "element-plus";

export default {
  name: "studentAddByExcel",
  created() {
    var parse = JSON.parse(window.localStorage.getItem('zjxClass_teacherinfo'));
    this.fileUpHead = {
      'tk': parse.Token
    }
  },
  data() {
    return {
      fileUpHead: {}
    }
  },
  methods: {}
}
</script>

<script setup>
import {ref} from 'vue'
import {ElMessage} from "element-plus";

const upload = ref()

const handleExceed = (files) => {
  upload.value.clearFiles()
  upload.value.handleStart(files[0])
}
const submitUpload = () => {
  upload.value.submit()

  ElMessage.success({
    message: JSON.stringify("添加成功"),
  })
}

</script>
<style scoped>

</style>